<template>
  <div class="company-user">
    <index-breadcrumb :breadcrumb-list="breadcrumbList" :isShow="true"></index-breadcrumb>
    <user-msg :operation-list="operationList"></user-msg>
  </div>
</template>

<script>
import UserMsg from "@/views/sys/companyUser/pages/editUser/includes/UserMsg";

export default {
  name: "CompanyUser",
  components: {
    UserMsg,
  },
  data() {
    return {
      operationList: [],
      breadcrumbList: [
        {
          title: "系统管理"
        },
        {
          title: "账号管理"
        },
      ],
      type: 2,
      currentItem: null,
    };
  },
  watch: {
    $route(){
      if(this.$route.query.type && this.$route.query.type == 1){
        this.breadcrumbList = [
          {
            title: "系统管理"
          },
          {
            title: "个人资料"
          },
        ]
      }else if(this.$route.query.row){
        this.breadcrumbList = [
          {
            title: "系统管理"
          },
          {
            title: "账号管理"
          },
        ]
        this.breadcrumbList.push({
            title: "编辑账号"
        })
      }else{
        this.breadcrumbList = [
          {
            title: "系统管理"
          },
          {
            title: "账号管理"
          },
        ]
        this.breadcrumbList.push({
            title: "创建账号"
        })
      }
      this.getOperationList();
    }
  },
  activated() {
    this.breadcrumbList= [
        {
          title: "系统管理"
        },
        {
          title: "账号管理"
        },
      ]
    if(this.$route.query.type && this.$route.query.type == 1){
      this.breadcrumbList = [
        {
          title: "系统管理"
        },
        {
          title: "个人资料"
        },
      ]
    }else if(this.$route.query.row){
      this.breadcrumbList.push({
          title: "编辑账号"
      })
    }else{
      this.breadcrumbList.push({
          title: "创建账号"
      })
    }
    this.getOperationList();
  },
  methods: {
    changeOneType(){
      this.currentItem = null
      this.type = 1
    },
    changeType(val){
      this.currentItem = val
      this.type = 2
    },
    getOperationList() {
      this.$store.state.permissionList.forEach(item => {
        const [itemName] = item.permission.split(":");
        if (itemName === "companyUser") {
          this.operationList = item.list.map(listItem => {
            return listItem.permission.split(":")[1];
          });
        }
        if (itemName === "project") {
          item.list.some(listItem => {
            const listItemType = listItem.permission.split(":")[1];
            if (listItemType === "edit") {
              this.operationList.push("project:edit");
              return true;
            }
            return false;
          });
        }
        if (itemName === "project") {
          item.list.some(listItem => {
            const listItemType = listItem.permission.split(":")[1];
            if (listItemType === "update") {
              this.operationList.push("project:update");
              return true;
            }
            return false;
          });
        }
        if (itemName === "permission") {
          item.list.some(listItem => {
            const listItemType = listItem.permission.split(":")[1];
            if (listItemType === "edit") {
              this.operationList.push("permission:edit");
              return true;
            }
            return false;
          });
        }
      });
    }
  }
};
</script>

<style lang="sass" scoped>

</style>
